﻿/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
**/

package com.chasekernan.hxnova.componenteditor.details;

import com.chasekernan.hxnova.componenteditor.DetailsPanel;
import com.chasekernan.hxnova.core.components.Bomb;
import org.aswing.JAdjuster;
import com.chasekernan.hxnova.componenteditor.ComponentEditorPanel;

class BombPanel extends DetailsPanel {

    private var minimumKillInput : JAdjuster;
    private var percentKillInput : JAdjuster;
    private var installationsDestroyedInput : JAdjuster;
    
    public function new() {
        super();
        
        minimumKillInput = DetailsPanel.createIntAdjuster(0, 10000);
        percentKillInput = DetailsPanel.createIntAdjuster(0, 1000); //to be converted to a float later
        installationsDestroyedInput = DetailsPanel.createIntAdjuster(0, 1000);
        
        addRowHaxe(createLeftLabel("Minimum Kill"), minimumKillInput, null);
        addRowHaxe(createLeftLabel("Percent Kill"), percentKillInput , createLeftLabel("/ 1000"));
        addRowHaxe(createLeftLabel("Installations Destroyed"), installationsDestroyedInput, null);
        
        allInputs = [minimumKillInput, percentKillInput, installationsDestroyedInput];
    }
    
    public override function loadFromComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var bomb = cast(ComponentEditorPanel.INSTANCE.editedComponent, Bomb);
        
        minimumKillInput.setValue(bomb.minimumKill);
        percentKillInput.setValue(Math.round(bomb.percentKill * 1000));
        installationsDestroyedInput.setValue(bomb.installationsDestroyed);
    }
    
    public override function saveToComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var bomb = cast(ComponentEditorPanel.INSTANCE.editedComponent, Bomb);
        
        bomb.minimumKill = minimumKillInput.getValue();
        bomb.percentKill = percentKillInput.getValue() / 1000.0;
        bomb.installationsDestroyed = installationsDestroyedInput.getValue();
    }
    
}